<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\facade\Db;
use think\facade\Request;
use think\facade\View;

class Brand
{
    public function brand()
    {
        $keywords = Request::post('keywords');
        $post = Request::post();
        $whereOr = [];
        $where = [];
        if (isset($keywords) && $keywords <> '') $where[] = ['brand_name', 'like', "%{$keywords}%"];
        if (isset($post['recommended']) && $post['recommended'] <> '') $where[] = ['recommended', '=', $post['recommended']];
        if (isset($post['if_show']) && count($post['if_show']) == 1) $where[] = ['if_show', 'in', $post['if_show']];
        if (isset($post['is_img']) && count($post['is_img']) == 1){
            if($post['is_img'][0] == 1){
                $where[] = ['brand_logo', '<>', ''];
            }else{
                $whereOr[] = ['brand_logo', '=', null];
                $whereOr[] = ['brand_logo', '=', ''];
            }

        }
//        View::assign('keyword',$keywords);
        View::assign($post);
        $brand = Db::name('brand')
            ->where($where)
            //->whereOr($whereOr)
            ->where(function ($q) use($whereOr){
                $q->whereOr($whereOr);
            })
            ->order('sort_order')
            ->select();
        View::assign('brand', $brand);
        return View::fetch();

    }
}